package com.shangpintechnology.sci;

import java.util.Vector;

import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

import com.shangpintechnology.sci.jni.NativeCall;


public class RifdEventRunnable  implements Runnable{
	 private NativeCall nc;
	private boolean open;
	private boolean init;
	public NativeCall getNc() {
		return NativeCall.singleton();
	}
	public void run() {
		 
		 
	while(true){
		
		if(!init){
			nc.initCOM();
			continue;
		}
		if(!open){
			nc.openCOM();
			continue;
		}
		nc.readEPC();
		byte[] b = nc.revEPC();
		if(null==b){
			continue;
		}
	///////
		 byte[] b2 = {1,1,1,1,1,1,1,1,11,1};
		 nc.writeEPC(b2,b2);
		 nc.readData();
		 nc.writeData(new byte[]{0,0,0,0,0,0,0,0}, b2);
		 ///////////
		String epc = nc.getHexString(b);
		System.out.println(epc);
		if(MainClass.getSingleton().handOutCard){
			MainClass.getSingleton().getCinfo().getRfidCode().setText(epc);
			//添加拍照
		}else{
		String vipCode  = MainClass.getSingleton().getDataModel().getVipCodebyRfid(epc);
		
		if(null ==vipCode ){
			System.out.println("unkownEpc");
			continue;
		}
		Vector accountInfo = MainClass.getSingleton().getDataModel().getHistoryPersonalInfo(vipCode);
		MainClass.getSingleton().getDataModel().setCurrentVipCode(vipCode);
		if(null==accountInfo){
			System.out.println("unkownVipCode");
			continue;
		}
		DefaultTableModel dtm =  (DefaultTableModel) MainClass.getSingleton().getSharedTodayTableModel();
		dtm.insertRow(0, accountInfo);
		DAO dao  = new DAO();
		dao.insertVipComeInEvent(vipCode,(String)accountInfo.get(1),(String)accountInfo.get(2), epc);
		
		}
		try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}catch(Exception e){
			e.printStackTrace();
		}
		
	}
	}	
		

	public RifdEventRunnable() {
		super(); 
		this.nc = new NativeCall();
		this.init = nc.initCOM();
		this.open = nc.openCOM();
	}
	 
	

}
